package com.surprise.bweb.vo;

import org.apache.commons.lang.StringUtils;

import com.surprise.base.entity.Address;
import com.surprise.base.util.JacksonUtils;
import com.surprise.bweb.bo.base.ChargePerson;
import com.surprise.bweb.bo.base.Director;
import com.surprise.db.entity.BUser;
import com.surprise.db.entity.Mall;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * MallVO.java
 * @author nick
 * @since 2016年2月15日
**/
@Data
@Accessors(chain = true)
@NoArgsConstructor
public class MallVO {
    private Long id;
    private String name = "";
    private String developer = "";
    private String operator = "";
    private Address address;
    private ChargePerson chargePerson;
    private Director director;
    private String logoPic = "";
    private String projectPic = "";
    private String idPic1;
    private String idPic2;
    private String cityId;
    private String districtid;
    private String qrcode = "";
    private String username;
    private String password;
    private String prefix;
    private String emchatGroupID;
    
    public MallVO(Mall mall, BUser buser) {
        if (buser != null) {
            this.setUsername(buser.getName()).setPassword(buser.getPassword());
        }
        this.setId(mall.getId())
                .setName(mall.getName()).setDeveloper(mall.getDeveloper())
                .setOperator(mall.getOperator())
                .setLogoPic(mall.getLogoPic()).setProjectPic(mall.getProjectPic())
                .setIdPic1(mall.getIdPic1()).setIdPic2(mall.getIdPic2())
                .setCityId(mall.getCityid() + "").setDistrictid(mall.getDistrictid() + "").setQrcode(mall.getQrcode())
                .setPrefix(mall.getPrefix()).setEmchatGroupID(mall.getEmchatGroupID());
        if (StringUtils.isNotEmpty(mall.getChargePerson())) {
            this.setChargePerson(JacksonUtils.fromJson(mall.getChargePerson(), ChargePerson.class));
        }
        if (StringUtils.isNotEmpty(mall.getDirector())) {
            this.setDirector(JacksonUtils.fromJson(mall.getDirector(), Director.class));
        }
        if (StringUtils.isNotEmpty(mall.getAddress())) {
            this.setAddress(JacksonUtils.fromJson(mall.getAddress(), Address.class));
        }
    }
}
